﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;


namespace mirror
{
    public class cRigidRenderable : cRenderable
    {
        protected Model mModel;
        public Matrix mTransform;

        public cRigidRenderable(Model model)
        {
            mModel = model;
            mTransform = Matrix.Identity;
        }

        public Model GetModel() { return mModel; }
        public Matrix GetTransform() { return mTransform; }

        public override void Render()
        {
            Camera camera = Camera.Instance;
            Matrix[] modelTransforms = new Matrix[mModel.Bones.Count];
            mModel.CopyAbsoluteBoneTransformsTo(modelTransforms);

            foreach (ModelMesh mesh in mModel.Meshes)
            {
                foreach (BasicEffect effect in mesh.Effects)
                {
                    //effect.EnableDefaultLighting();

                    effect.View = camera.ViewMatrix;
                    effect.Projection = camera.ProjectionMatrix;
                    effect.World = modelTransforms[mesh.ParentBone.Index] * mTransform;
                }
                mesh.Draw();
            }
        }

        ~cRigidRenderable()
        {
            cRenderManager.Instance.RemoveRigid(this);
        }
    }
}